package com.giveu.signature.common.service.impl;

import java.io.File;
import java.io.OutputStream;
import java.util.Map;

import com.giveu.signature.bean.TemplateHtmlParam;
import com.giveu.signature.common.document.pdf.itext.PdfItextUtil;
import com.giveu.signature.common.service.GenModelService;



public class PdfServiceImpl extends GenModelService {

	@Override
	public void genPdfOutputStream(OutputStream out, TemplateHtmlParam tm, Map<String, Object> map) throws Exception {
		String tempPath = "template"+File.separator+tm.getTempKey()+tm.getFastPath().substring(tm.getFastPath().lastIndexOf("."));
		if(!new File(tempPath).isFile()){
			com.giveu.common.utils.FileUtil.download(tm.getFastPath(), tempPath);
		}
		out.write(PdfItextUtil.getReplaceRegionAndConverts(tempPath, map));
	}
}
